package com.zqxq.lottery.entity.o2o.sys;

import com.baomidou.mybatisplus.plugins.Page;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.common.utils.PageCopy;
import com.zqxq.lottery.entity.po.sys.SysNewsPO;
import com.zqxq.lottery.entity.vo.sys.SysNewsVO;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:14
 */
public class SysNewsO2O {

    public static SysNewsVO toVO(SysNewsPO po) {
        if (po == null) {
            return null;
        }
        SysNewsVO sysNewsVO = new SysNewsVO();
        sysNewsVO.setId(DispatcherUtils.parseString(po.getId()));
        sysNewsVO.setTitle(po.getTitle());
        sysNewsVO.setClassify(po.getClassify());
        sysNewsVO.setImgUrl(po.getImg_url());
        sysNewsVO.setLinkUrl(po.getLink_url());
        sysNewsVO.setContent(po.getContent());
        sysNewsVO.setAuthor(po.getAuthor());
        sysNewsVO.setSort(DispatcherUtils.parseString(po.getSort()));
        sysNewsVO.setStatus(DispatcherUtils.parseString(po.getStatus()));
        sysNewsVO.setReader(DispatcherUtils.parseString(po.getReader()));
        sysNewsVO.setSource(DispatcherUtils.parseString(po.getSource()));
        sysNewsVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        sysNewsVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return sysNewsVO;
    }

    public static Page<SysNewsVO> toPageVO(Page<SysNewsPO> page){
        Page<SysNewsVO> result = PageCopy.copyProperty(page, null);
        if(page != null){
            List<SysNewsPO> poList = page.getRecords();
            List<SysNewsVO> voList = toVOList(poList);
            result.setRecords(voList);
        }
        return result;
    }

    public static SysNewsPO toPO(SysNewsVO vo) {
        if (vo == null) {
            return null;
        }
        SysNewsPO sysNewsPO = new SysNewsPO();
        sysNewsPO.setId(DispatcherUtils.parseLong(vo.getId()));
        sysNewsPO.setTitle(vo.getTitle());
        sysNewsPO.setClassify(vo.getClassify());
        sysNewsPO.setImg_url(vo.getImgUrl());
        sysNewsPO.setLink_url(vo.getLinkUrl());
        sysNewsPO.setContent(vo.getContent());
        sysNewsPO.setAuthor(vo.getAuthor());
        sysNewsPO.setSort(DispatcherUtils.parseInteger(vo.getSort()));
        sysNewsPO.setStatus(DispatcherUtils.parseInteger(vo.getStatus()));
        sysNewsPO.setReader(DispatcherUtils.parseInteger(vo.getReader()));
        sysNewsPO.setSource(DispatcherUtils.parseInteger(vo.getSource()));
        sysNewsPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        sysNewsPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return sysNewsPO;
    }

    public static List<SysNewsVO> toVOList(List<SysNewsPO> list){
        List<SysNewsVO> result = new ArrayList();
        if(list != null && list.size() > 0){
            for (SysNewsPO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }


}
